package problem24;

class Solution2 {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode newHead = new ListNode();
        newHead.next = head;
        ListNode curA = newHead;
        while(curA != null && curA.next != null) {
            ListNode curB = curA.next;
            ListNode curC = curB.next;

            curA.next = curC;
            if(curC!=null) {
                curB.next = curC.next;
                curC.next = curB;
            }else {
                curA.next = curB;
            }

            curA = curB;
            System.out.println(curA.val);
        }

        return newHead.next;
    }
}